home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / shaders / k3d_brickbump.sl < prev    next >
Encoding:
Text File  |  2004-07-23  |  2.7 KB  |  80 lines

  1. /*
  2.  * brickbump.sl -- displacement shader for bricks.
  3.  *
  4.  * Description:
  5.  *   Makes displacements for a wall of bricks.  This is the companion
  6.  *   shader to the surface "brick" shader.  The parameters work exactly
  7.  *   the same.  Of course, you can use it with any surface shader, and
  8.  *   in fact matte or plastic gives those nice white cinder block walls.
  9.  *   However, if you do use it with "brick", the parameters MUST match,
  10.  *   or your bricks will look very strange.
  11.  * 
  12.  * Parameters:
  13.  *    brickwidth                Width of a brick (in st space)
  14.  *    brickheight               Height of a brick (in st space)
  15.  *    mortarthickness           Thickness of the mortar (in st space)
  16.  *    rowvary                   How much does each row shift?
  17.  *    jagged                    How much do bricks deviate from squares?
  18.  *    pitting                   The amplitude of the "pits" on the face of
  19.  *                                 the bricks.
  20.  *    pockfrequency             The st frequency of the pits.
  21.  *    groovedepth               The depth of the grooves between bricks.
  22.  *
  23.  * AUTHOR: written by Larry Gritz, 1992 (and subsequently modified)
  24.  */
  25.  
  26. #include "k3d_noises.h"
  27. #include "k3d_patterns.h"
  28.  
  29. displacement k3d_brickbump(float jagged = 0.006;
  30.                float brickwidth = .25, brickheight = .08;
  31.                float mortarthickness = .01;
  32.                float rowvary = .25, pitting = 0.01;
  33.                float pockfrequency = 10, groovedepth = 0.01;)
  34. {
  35. #define sqr(x) ((x)*(x))
  36.   float sbrick, tbrick;
  37.   float ss, tt;
  38.   float fact, disp;
  39.   uniform float BMWIDTH = (brickwidth + mortarthickness);
  40.   uniform float BMHEIGHT = (brickheight + mortarthickness);
  41.   uniform float MWF = (mortarthickness * 0.5 / BMWIDTH);
  42.   uniform float MHF = (mortarthickness * 0.5 / BMHEIGHT);
  43.  
  44.   basicbrick(s, t, BMWIDTH, BMHEIGHT, 0.5, 0.2, 1, jagged, sbrick, tbrick, ss,
  45.          tt);
  46.  
  47.   fact = 1;
  48.   disp = 0;
  49.   if(tt < MHF)
  50.     {
  51.       /* We're in the top horizontal groove */
  52.       disp = groovedepth * (sqr((tt) / MHF) - 1);
  53.     }
  54.   else if(tt > (1.0 - MHF))
  55.     {
  56.       /* Bottom horizontal groove */
  57.       disp = groovedepth * (sqr((1 - tt) / MHF) - 1);
  58.     }
  59.   if(ss < MWF)
  60.     {
  61.       disp = min(disp, 0.85 * groovedepth * (sqr(ss / MWF) - 1));
  62.     }
  63.   else if(ss > (1.0 - MWF))
  64.     {
  65.       disp = min(disp, 0.85 * groovedepth * (sqr((1 - ss) / MWF) - 1));
  66.     }
  67.  
  68.   fact = smoothstep(0, 1.3 * MHF, tt) - smoothstep(1.0 - 1.3 * MHF, 1, tt);
  69.   fact *= (smoothstep(0, 1.3 * MWF, ss) - smoothstep(1.0 - 1.3 * MWF, 1, ss));
  70.   fact = pitting * (0.75 * fact + 0.25);
  71.   disp -=
  72.     fact *
  73.     pow(noise
  74.     ((ss + sbrick) * pockfrequency / BMHEIGHT,
  75.      (tt + tbrick) * pockfrequency / BMWIDTH), 0.25);
  76.  
  77.   P += disp * normalize(N);
  78.   N = calculatenormal(P);
  79. }
  80.